package com.kadron.base;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.kadron.common.KUtil;
import com.kadron.enumeration.KLang;

@MappedSuperclass
public abstract class KTBase extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4200192117978720302L;
	
	protected String name_en="";
	protected String name_sr="";
	protected String name_es="";

	protected String desc_en="";
	protected String desc_sr="";
	protected String desc_es="";

	public KTBase() {
		super();
	}
	
	public KTBase(String name_en, String name_sr, String name_es,
			String desc_en, String desc_sr, String desc_es) {
		super();
		this.name_en = name_en;
		this.name_sr = name_sr;
		this.name_es = name_es;
		this.desc_en = desc_en;
		this.desc_sr = desc_sr;
		this.desc_es = desc_es;
	}

	@Column(name="name_en")
	public String getName_en() {
		return name_en;
	}

	public void setName_en(String name_en) {
		this.name_en = name_en;
	}

	@Column(name="name_sr")
	public String getName_sr() {
		return name_sr;
	}

	public void setName_sr(String name_sr) {
		this.name_sr = name_sr;
	}

	@Column(name="name_es")
	public String getName_es() {
		return name_es;
	}

	public void setName_es(String name_es) {
		this.name_es = name_es;
	}

	@Column(name="desc_en",columnDefinition="BLOB")
	public String getDesc_en() {
		return desc_en;
	}

	public void setDesc_en(String desc_en) {
		this.desc_en = desc_en;
	}

	@Column(name="desc_sr",columnDefinition="BLOB")
	public String getDesc_sr() {
		return desc_sr;
	}

	public void setDesc_sr(String desc_sr) {
		this.desc_sr = desc_sr;
	}

	@Column(name="desc_es",columnDefinition="BLOB")
	public String getDesc_es() {
		return desc_es;
	}

	public void setDesc_es(String desc_es) {
		this.desc_es = desc_es;
	}
	
	@Transient
	public KTBase update(KTBase newvalue) {
		setName_en(newvalue.getName_en());
		setName_sr(newvalue.getName_sr());
		setName_es(newvalue.getName_es());
		setDesc_en(newvalue.getDesc_en());
		setDesc_sr(newvalue.getDesc_sr());
		setDesc_es(newvalue.getDesc_es());
		return this;
	}
	
	@Transient
	public String getDesc(String lang) {
		String value = "";
		if (KUtil.isEmpty(lang) || lang.equalsIgnoreCase(KLang.EN.name())) {
			value = getDesc_en();
		} else if (lang.equalsIgnoreCase(KLang.ES.name())) {
			value = getDesc_es();
		} else {
			value = getDesc_sr();
		}
		if (KUtil.isEmpty(value)) {
			value = getDesc_en();
		}
		return value;
	}

	@Transient
	public String getName(String lang) {
		String value = "";
		if (KUtil.isEmpty(lang) || lang.equalsIgnoreCase(KLang.EN.name())) {
			value = getName_en();
		} else if (lang.equalsIgnoreCase(KLang.ES.name())) {
			value = getName_es();
		} else {
			value = getName_sr();
		}
		if (KUtil.isEmpty(value)) {
			value = getName_en();
		}
		return value;
	}
}
